﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections;

namespace BWindingMachine
{
    public partial class ParameterForm : Form
    {
        public MainForm _frm_MainForm = null;
        private string ProductNumber = "";
        private string ProductName = "";

        public ParameterForm()
        {
            InitializeComponent();
        }

        private void btn_Close_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            textBox14.Text = Convert.ToString(Data.Encode1);
            textBox17.Text = Convert.ToString(Data.Encode2);
        }

        private void button43_Click(object sender, EventArgs e)
        {
            Data.Send("output#43#0#");
        }

        private void button7_Click(object sender, EventArgs e)
        {
            Data.bilichi1 = Data.Encode1 / 1000;
            txt_bilichi1.Text = Convert.ToString(Data.Encode1 / 1000);
        }

        private void button6_Click(object sender, EventArgs e)
        {
            Data.Send("output#44#0#");
        }

        private void button5_Click(object sender, EventArgs e)
        {
            Data.bilichi2 = Data.Encode2 / 1000;
            txt_bilichi2.Text = Convert.ToString(Data.Encode2 / 1000);
        }

        private void btn_1zongchang_Click(object sender, EventArgs e)
        {
            try
            {
                KeyBoardForm _frm_KeyBoardForm = new KeyBoardForm();
                _frm_KeyBoardForm.ShowDialog();
                if (_frm_KeyBoardForm.IsOk)
                {
                    txt_1zongchang.Text = _frm_KeyBoardForm.ReturnValue;
                }
                _frm_KeyBoardForm.Dispose();
            }
            catch
            {
            }
        }

        private void btn_2zongchang_Click(object sender, EventArgs e)
        {
            try
            {
                KeyBoardForm _frm_KeyBoardForm = new KeyBoardForm();
                _frm_KeyBoardForm.ShowDialog();
                if (_frm_KeyBoardForm.IsOk)
                {
                    txt_2zongchang.Text = _frm_KeyBoardForm.ReturnValue;
                }
                _frm_KeyBoardForm.Dispose();
            }
            catch
            {
            }
        }

        private void btn_1yuchuchang_Click(object sender, EventArgs e)
        {
            try
            {
                KeyBoardForm _frm_KeyBoardForm = new KeyBoardForm();
                _frm_KeyBoardForm.ShowDialog();
                if (_frm_KeyBoardForm.IsOk)
                {
                    txt_1yuchuchang.Text = _frm_KeyBoardForm.ReturnValue;
                }
                _frm_KeyBoardForm.Dispose();
            }
            catch
            {
            }
        }

        private void btn_2yuchuchang_Click(object sender, EventArgs e)
        {
            try
            {
                KeyBoardForm _frm_KeyBoardForm = new KeyBoardForm();
                _frm_KeyBoardForm.ShowDialog();
                if (_frm_KeyBoardForm.IsOk)
                {
                    txt_2yuchuchang.Text = _frm_KeyBoardForm.ReturnValue;
                }
                _frm_KeyBoardForm.Dispose();
            }
            catch
            {
            }
        }

        private void btn_mansuchang_Click(object sender, EventArgs e)
        {
            try
            {
                KeyBoardForm _frm_KeyBoardForm = new KeyBoardForm();
                _frm_KeyBoardForm.ShowDialog();
                if (_frm_KeyBoardForm.IsOk)
                {
                    txt_mansuchang.Text = _frm_KeyBoardForm.ReturnValue;
                }
                _frm_KeyBoardForm.Dispose();
            }
            catch
            {
            }
        }

        private void btn_jiasuchang_Click(object sender, EventArgs e)
        {
            try
            {
                KeyBoardForm _frm_KeyBoardForm = new KeyBoardForm();
                _frm_KeyBoardForm.ShowDialog();
                if (_frm_KeyBoardForm.IsOk)
                {
                    txt_jiasuchang.Text = _frm_KeyBoardForm.ReturnValue;
                }
                _frm_KeyBoardForm.Dispose();
            }
            catch
            {
            }
        }

        private void btn_jiansuchang_Click(object sender, EventArgs e)
        {
            try
            {
                KeyBoardForm _frm_KeyBoardForm = new KeyBoardForm();
                _frm_KeyBoardForm.ShowDialog();
                if (_frm_KeyBoardForm.IsOk)
                {
                    txt_jiansuchang.Text = _frm_KeyBoardForm.ReturnValue;
                }
                _frm_KeyBoardForm.Dispose();
            }
            catch
            {
            }
        }

        private void btn_songbu_Click(object sender, EventArgs e)
        {
            try
            {
                KeyBoardForm _frm_KeyBoardForm = new KeyBoardForm();
                _frm_KeyBoardForm.ShowDialog();
                if (_frm_KeyBoardForm.IsOk)
                {
                    txt_songbu.Text = _frm_KeyBoardForm.ReturnValue;
                }
                _frm_KeyBoardForm.Dispose();
            }
            catch
            {
            }
        }

        private void btn_xuanbu_Click(object sender, EventArgs e)
        {
            try
            {
                KeyBoardForm _frm_KeyBoardForm = new KeyBoardForm();
                _frm_KeyBoardForm.ShowDialog();
                if (_frm_KeyBoardForm.IsOk)
                {
                    txt_xuanbu.Text = _frm_KeyBoardForm.ReturnValue;
                }
                _frm_KeyBoardForm.Dispose();
            }
            catch
            {
            }
        }

        private void btn_raoxianman_Click(object sender, EventArgs e)
        {
            try
            {
                KeyBoardForm _frm_KeyBoardForm = new KeyBoardForm();
                _frm_KeyBoardForm.ShowDialog();
                if (_frm_KeyBoardForm.IsOk)
                {
                    txt_raoxianman.Text = _frm_KeyBoardForm.ReturnValue;
                }
                _frm_KeyBoardForm.Dispose();
            }
            catch
            {
            }
        }

        private void btn_raoxiankuai_Click(object sender, EventArgs e)
        {
            try
            {
                KeyBoardForm _frm_KeyBoardForm = new KeyBoardForm();
                _frm_KeyBoardForm.ShowDialog();
                if (_frm_KeyBoardForm.IsOk)
                {
                    txt_raoxiankuai.Text = _frm_KeyBoardForm.ReturnValue;
                }
                _frm_KeyBoardForm.Dispose();
            }
            catch
            {
            }
        }

        private void btn_chuanbu_Click(object sender, EventArgs e)
        {
            try
            {
                KeyBoardForm _frm_KeyBoardForm = new KeyBoardForm();
                _frm_KeyBoardForm.ShowDialog();
                if (_frm_KeyBoardForm.IsOk)
                {
                    txt_chuanbu.Text = _frm_KeyBoardForm.ReturnValue;
                }
                _frm_KeyBoardForm.Dispose();
            }
            catch
            {
            }
        }

        private void btn_shangjia1_Click(object sender, EventArgs e)
        {
            try
            {
                KeyBoardForm _frm_KeyBoardForm = new KeyBoardForm();
                _frm_KeyBoardForm.ShowDialog();
                if (_frm_KeyBoardForm.IsOk)
                {
                    txt_shangjia1.Text = _frm_KeyBoardForm.ReturnValue;
                }
                _frm_KeyBoardForm.Dispose();
            }
            catch
            {
            }
        }

        private void btn_ding1_Click(object sender, EventArgs e)
        {
            try
            {
                KeyBoardForm _frm_KeyBoardForm = new KeyBoardForm();
                _frm_KeyBoardForm.ShowDialog();
                if (_frm_KeyBoardForm.IsOk)
                {
                    txt_ding1.Text = _frm_KeyBoardForm.ReturnValue;
                }
                _frm_KeyBoardForm.Dispose();
            }
            catch
            {
            }
        }

        private void btn_xiaxi2_Click(object sender, EventArgs e)
        {
            try
            {
                KeyBoardForm _frm_KeyBoardForm = new KeyBoardForm();
                _frm_KeyBoardForm.ShowDialog();
                if (_frm_KeyBoardForm.IsOk)
                {
                    txt_xiaxi2.Text = _frm_KeyBoardForm.ReturnValue;
                }
                _frm_KeyBoardForm.Dispose();
            }
            catch
            {
            }
        }

        private void btn_xiaxi1_Click(object sender, EventArgs e)
        {
            try
            {
                KeyBoardForm _frm_KeyBoardForm = new KeyBoardForm();
                _frm_KeyBoardForm.ShowDialog();
                if (_frm_KeyBoardForm.IsOk)
                {
                    txt_xiaxi1.Text = _frm_KeyBoardForm.ReturnValue;
                }
                _frm_KeyBoardForm.Dispose();
            }
            catch
            {
            }
        }

        private void btn_shangjia2_Click(object sender, EventArgs e)
        {
            try
            {
                KeyBoardForm _frm_KeyBoardForm = new KeyBoardForm();
                _frm_KeyBoardForm.ShowDialog();
                if (_frm_KeyBoardForm.IsOk)
                {
                    txt_shangjia2.Text = _frm_KeyBoardForm.ReturnValue;
                }
                _frm_KeyBoardForm.Dispose();
            }
            catch
            {
            }
        }

        private void btn_ding2_Click(object sender, EventArgs e)
        {
            try
            {
                KeyBoardForm _frm_KeyBoardForm = new KeyBoardForm();
                _frm_KeyBoardForm.ShowDialog();
                if (_frm_KeyBoardForm.IsOk)
                {
                    txt_ding2.Text = _frm_KeyBoardForm.ReturnValue;
                }
                _frm_KeyBoardForm.Dispose();
            }
            catch
            {
            }
        }

        private void btn_qie2_Click(object sender, EventArgs e)
        {
            try
            {
                KeyBoardForm _frm_KeyBoardForm = new KeyBoardForm();
                _frm_KeyBoardForm.ShowDialog();
                if (_frm_KeyBoardForm.IsOk)
                {
                    txt_qie2.Text = _frm_KeyBoardForm.ReturnValue;
                }
                _frm_KeyBoardForm.Dispose();
            }
            catch
            {
            }
        }

        private void btn_shangda2_Click(object sender, EventArgs e)
        {
            try
            {
                KeyBoardForm _frm_KeyBoardForm = new KeyBoardForm();
                _frm_KeyBoardForm.ShowDialog();
                if (_frm_KeyBoardForm.IsOk)
                {
                    txt_shangda2.Text = _frm_KeyBoardForm.ReturnValue;
                }
                _frm_KeyBoardForm.Dispose();
            }
            catch
            {
            }
        }

        private void btn_chu_Click(object sender, EventArgs e)
        {
            try
            {
                KeyBoardForm _frm_KeyBoardForm = new KeyBoardForm();
                _frm_KeyBoardForm.ShowDialog();
                if (_frm_KeyBoardForm.IsOk)
                {
                    txt_chu.Text = _frm_KeyBoardForm.ReturnValue;
                }
                _frm_KeyBoardForm.Dispose();
            }
            catch
            {
            }
        }

        private void btn_shangda1_Click(object sender, EventArgs e)
        {
            try
            {
                KeyBoardForm _frm_KeyBoardForm = new KeyBoardForm();
                _frm_KeyBoardForm.ShowDialog();
                if (_frm_KeyBoardForm.IsOk)
                {
                    txt_shangda1.Text = _frm_KeyBoardForm.ReturnValue;
                }
                _frm_KeyBoardForm.Dispose();
            }
            catch
            {
            }
        }

        private void btn_qie1_Click(object sender, EventArgs e)
        {
            try
            {
                KeyBoardForm _frm_KeyBoardForm = new KeyBoardForm();
                _frm_KeyBoardForm.ShowDialog();
                if (_frm_KeyBoardForm.IsOk)
                {
                    txt_qie1.Text = _frm_KeyBoardForm.ReturnValue;
                }
                _frm_KeyBoardForm.Dispose();
            }
            catch
            {
            }
        }

        private void btn_songzhoujia_Click(object sender, EventArgs e)
        {
            try
            {
                KeyBoardForm _frm_KeyBoardForm = new KeyBoardForm();
                _frm_KeyBoardForm.ShowDialog();
                if (_frm_KeyBoardForm.IsOk)
                {
                    txt_songzhoujia.Text = _frm_KeyBoardForm.ReturnValue;
                }
                _frm_KeyBoardForm.Dispose();
            }
            catch
            {
            }
        }

        private void btn_chuanzhoujia_Click(object sender, EventArgs e)
        {
            try
            {
                KeyBoardForm _frm_KeyBoardForm = new KeyBoardForm();
                _frm_KeyBoardForm.ShowDialog();
                if (_frm_KeyBoardForm.IsOk)
                {
                    txt_chuanzhoujia.Text = _frm_KeyBoardForm.ReturnValue;
                }
                _frm_KeyBoardForm.Dispose();
            }
            catch
            {
            }
        }

        private void btn_xuanzhoujia_Click(object sender, EventArgs e)
        {
            try
            {
                KeyBoardForm _frm_KeyBoardForm = new KeyBoardForm();
                _frm_KeyBoardForm.ShowDialog();
                if (_frm_KeyBoardForm.IsOk)
                {
                    txt_xuanzhoujia.Text = _frm_KeyBoardForm.ReturnValue;
                }
                _frm_KeyBoardForm.Dispose();
            }
            catch
            {
            }
        }

        private void btn_raozhoujia_Click(object sender, EventArgs e)
        {
            try
            {
                KeyBoardForm _frm_KeyBoardForm = new KeyBoardForm();
                _frm_KeyBoardForm.ShowDialog();
                if (_frm_KeyBoardForm.IsOk)
                {
                    txt_raozhoujia.Text = _frm_KeyBoardForm.ReturnValue;
                }
                _frm_KeyBoardForm.Dispose();
            }
            catch
            {
            }
        }

        private void btn_fu1_Click(object sender, EventArgs e)
        {
            try
            {
                KeyBoardForm _frm_KeyBoardForm = new KeyBoardForm();
                _frm_KeyBoardForm.ShowDialog();
                if (_frm_KeyBoardForm.IsOk)
                {
                    txt_fu1.Text = _frm_KeyBoardForm.ReturnValue;
                }
                _frm_KeyBoardForm.Dispose();
            }
            catch
            {
            }
        }

        private void btn_xuan1_Click(object sender, EventArgs e)
        {
            try
            {
                KeyBoardForm _frm_KeyBoardForm = new KeyBoardForm();
                _frm_KeyBoardForm.ShowDialog();
                if (_frm_KeyBoardForm.IsOk)
                {
                    txt_xuan1.Text = _frm_KeyBoardForm.ReturnValue;
                }
                _frm_KeyBoardForm.Dispose();
            }
            catch
            {
            }
        }

        private void btn_songzhoujian_Click(object sender, EventArgs e)
        {
            try
            {
                KeyBoardForm _frm_KeyBoardForm = new KeyBoardForm();
                _frm_KeyBoardForm.ShowDialog();
                if (_frm_KeyBoardForm.IsOk)
                {
                    txt_songzhoujian.Text = _frm_KeyBoardForm.ReturnValue;
                }
                _frm_KeyBoardForm.Dispose();
            }
            catch
            {
            }
        }

        private void btn_chuanzhoujian_Click(object sender, EventArgs e)
        {
            try
            {
                KeyBoardForm _frm_KeyBoardForm = new KeyBoardForm();
                _frm_KeyBoardForm.ShowDialog();
                if (_frm_KeyBoardForm.IsOk)
                {
                    txt_chuanzhoujian.Text = _frm_KeyBoardForm.ReturnValue;
                }
                _frm_KeyBoardForm.Dispose();
            }
            catch
            {
            }
        }

        private void btn_xuanzhoujian_Click(object sender, EventArgs e)
        {
            try
            {
                KeyBoardForm _frm_KeyBoardForm = new KeyBoardForm();
                _frm_KeyBoardForm.ShowDialog();
                if (_frm_KeyBoardForm.IsOk)
                {
                    txt_xuanzhoujian.Text = _frm_KeyBoardForm.ReturnValue;
                }
                _frm_KeyBoardForm.Dispose();
            }
            catch
            {
            }
        }

        private void btn_raozhoujian_Click(object sender, EventArgs e)
        {
            try
            {
                KeyBoardForm _frm_KeyBoardForm = new KeyBoardForm();
                _frm_KeyBoardForm.ShowDialog();
                if (_frm_KeyBoardForm.IsOk)
                {
                    txt_raozhoujian.Text = _frm_KeyBoardForm.ReturnValue;
                }
                _frm_KeyBoardForm.Dispose();
            }
            catch
            {
            }
        }

        private void btn_fu2_Click(object sender, EventArgs e)
        {
            try
            {
                KeyBoardForm _frm_KeyBoardForm = new KeyBoardForm();
                _frm_KeyBoardForm.ShowDialog();
                if (_frm_KeyBoardForm.IsOk)
                {
                    txt_fu2.Text = _frm_KeyBoardForm.ReturnValue;
                }
                _frm_KeyBoardForm.Dispose();
            }
            catch
            {
            }
        }

        private void btn_xuan2_Click(object sender, EventArgs e)
        {
            try
            {
                KeyBoardForm _frm_KeyBoardForm = new KeyBoardForm();
                _frm_KeyBoardForm.ShowDialog();
                if (_frm_KeyBoardForm.IsOk)
                {
                    txt_xuan2.Text = _frm_KeyBoardForm.ReturnValue;
                }
                _frm_KeyBoardForm.Dispose();
            }
            catch
            {
            }
        }

        private void ParameterForm_Load(object sender, EventArgs e)
        {
            txt_ProductNumber.Text = _frm_MainForm.SetProductNumber;
            txt_ProductName.Text = _frm_MainForm.SetProductName;

            // SQL查询条件
            ProductNumber = _frm_MainForm.SetProductNumber;
            ProductName = _frm_MainForm.SetProductName;

            Queue que = new Queue();

            try
            {
                string sql = "SELECT * FROM tb_Length WHERE product_number = '" + ProductNumber + "'";
                DataSet dsOne = SQLiteHelper.ExecuteDataset(sql);
                DataTable dtOne = dsOne.Tables[0];

                DataRow _tmp = dtOne.Rows[0];

                // Text
                txt_1zongchang.Text = _tmp["zongchang1"].ToString();
                txt_2zongchang.Text = _tmp["zongchang2"].ToString();
                txt_1yuchuchang.Text = _tmp["yuchuchang1"].ToString();
                txt_2yuchuchang.Text = _tmp["yuchuchang2"].ToString();
                txt_mansuchang.Text = _tmp["mansuchang"].ToString();
                txt_jiasuchang.Text = _tmp["jiasuchang"].ToString();
                txt_jiansuchang.Text = _tmp["jiansuchang"].ToString();
                
                // ListView
                que.Enqueue(_tmp["product_number"].ToString());
                que.Enqueue(_tmp["product_name"].ToString());
                que.Enqueue(_tmp["zongchang1"].ToString());
                que.Enqueue(_tmp["zongchang2"].ToString());
                que.Enqueue(_tmp["yuchuchang1"].ToString());
                que.Enqueue(_tmp["yuchuchang2"].ToString());
                que.Enqueue(_tmp["mansuchang"].ToString());
                que.Enqueue(_tmp["jiasuchang"].ToString());
                que.Enqueue(_tmp["jiansuchang"].ToString());
                ClassListViewOperate.AddOneRow(ref listView_Length, que);
                que.Clear();
            }
            catch
            {
                // MessageBox.Show(ex.Message);
            }
            try
            {
                string sql = "SELECT * FROM tb_Speed WHERE product_number = '" + ProductNumber + "'";
                DataSet dsOne = SQLiteHelper.ExecuteDataset(sql);
                DataTable dtOne = dsOne.Tables[0];

                DataRow _tmp = dtOne.Rows[0];

                // Text
                txt_songbu.Text = _tmp["songbu"].ToString();
                txt_chuanbu.Text = _tmp["chuanbu"].ToString();
                txt_xuanbu.Text = _tmp["xuanbu"].ToString();
                txt_raoxianman.Text = _tmp["raoxianman"].ToString();
                txt_raoxiankuai.Text = _tmp["raoxiankuai"].ToString();
                
                // ListView
                que.Enqueue(_tmp["product_number"].ToString());
                que.Enqueue(_tmp["product_name"].ToString());
                que.Enqueue(_tmp["songbu"].ToString());
                que.Enqueue(_tmp["chuanbu"].ToString());
                que.Enqueue(_tmp["xuanbu"].ToString());
                que.Enqueue(_tmp["raoxianman"].ToString());
                que.Enqueue(_tmp["raoxiankuai"].ToString());
                
                ClassListViewOperate.AddOneRow(ref listView_Speed, que);
                que.Clear();
            }
            catch
            {
                //MessageBox.Show(ex.Message);
            }
            try
            {
                string sql = "SELECT * FROM tb_Delay WHERE product_number = '" + ProductNumber + "'";
                DataSet dsOne = SQLiteHelper.ExecuteDataset(sql);
                DataTable dtOne = dsOne.Tables[0];

                DataRow _tmp = dtOne.Rows[0];

                // Text
                txt_shangjia1.Text = _tmp["shangjia1"].ToString();
                txt_ding1.Text = _tmp["ding1"].ToString();
                txt_xiaxi1.Text = _tmp["xiaxi1"].ToString();
                txt_shangjia2.Text = _tmp["shangjia2"].ToString();
                txt_ding2.Text = _tmp["ding2"].ToString();

                txt_xiaxi2.Text = _tmp["xiaxi2"].ToString();
                txt_shangda1.Text = _tmp["shangda1"].ToString();
                txt_qie1.Text = _tmp["qie1"].ToString();
                txt_chu.Text = _tmp["chu"].ToString();
                txt_shangda2.Text = _tmp["shangda2"].ToString();
                txt_qie2.Text = _tmp["qie2"].ToString();

                // ListView
                que.Enqueue(_tmp["product_number"].ToString());
                que.Enqueue(_tmp["product_name"].ToString());
                que.Enqueue(_tmp["shangjia1"].ToString());
                que.Enqueue(_tmp["ding1"].ToString());
                que.Enqueue(_tmp["xiaxi1"].ToString());
                que.Enqueue(_tmp["shangjia2"].ToString());
                que.Enqueue(_tmp["ding2"].ToString());

                que.Enqueue(_tmp["xiaxi2"].ToString());
                que.Enqueue(_tmp["shangda1"].ToString());
                que.Enqueue(_tmp["qie1"].ToString());
                que.Enqueue(_tmp["chu"].ToString());
                que.Enqueue(_tmp["shangda2"].ToString());
                que.Enqueue(_tmp["qie2"].ToString());

                ClassListViewOperate.AddOneRow(ref listView_Delay, que);
                que.Clear();
            }
            catch
            {
                //MessageBox.Show(ex.Message);
            }

            try
            {
                string sql = "SELECT * FROM tb_Parameter WHERE product_number = '" + ProductNumber + "'";
                DataSet dsOne = SQLiteHelper.ExecuteDataset(sql);
                DataTable dtOne = dsOne.Tables[0];

                DataRow _tmp = dtOne.Rows[0];

                // Text
                txt_songzhoujia.Text = _tmp["songzhoujia"].ToString();
                txt_songzhoujian.Text = _tmp["songzhoujian"].ToString();
                txt_chuanzhoujia.Text = _tmp["chuanzhoujia"].ToString();
                txt_chuanzhoujian.Text = _tmp["chuanzhoujian"].ToString();
                txt_xuanzhoujia.Text = _tmp["xuanzhoujia"].ToString();
                txt_xuanzhoujian.Text = _tmp["xuanzhoujian"].ToString();
                txt_raozhoujia.Text = _tmp["raozhoujia"].ToString();
                txt_raozhoujian.Text = _tmp["raozhoujian"].ToString();
                txt_fu1.Text = _tmp["fu1"].ToString();
                txt_fu2.Text = _tmp["fu2"].ToString();
                txt_xuan1.Text = _tmp["xuan1"].ToString();
                txt_xuan2.Text = _tmp["xuan2"].ToString();

                // ListView
                que.Enqueue(_tmp["product_number"].ToString());
                que.Enqueue(_tmp["product_name"].ToString());
                que.Enqueue(_tmp["songzhoujia"].ToString());
                que.Enqueue(_tmp["songzhoujian"].ToString());
                que.Enqueue(_tmp["chuanzhoujia"].ToString());
                que.Enqueue(_tmp["chuanzhoujian"].ToString());
                que.Enqueue(_tmp["xuanzhoujia"].ToString());
                que.Enqueue(_tmp["xuanzhoujian"].ToString());
                que.Enqueue(_tmp["raozhoujia"].ToString());
                que.Enqueue(_tmp["raozhoujian"].ToString());
                que.Enqueue(_tmp["fu1"].ToString());
                que.Enqueue(_tmp["fu2"].ToString());
                que.Enqueue(_tmp["xuan1"].ToString());
                que.Enqueue(_tmp["xuan2"].ToString());

                ClassListViewOperate.AddOneRow(ref listView_Param, que);
                que.Clear();
            }
            catch
            {
                //MessageBox.Show(ex.Message);
            }



            try
            {
                string sql = "SELECT * FROM tb_bilichi WHERE product_number = '" + ProductNumber + "'";
                DataSet dsOne = SQLiteHelper.ExecuteDataset(sql);
                DataTable dtOne = dsOne.Tables[0];

                DataRow _tmp = dtOne.Rows[0];

                // Text
                txt_bilichi1.Text = _tmp["bilichi1"].ToString();
                txt_bilichi2.Text = _tmp["bilichi2"].ToString();

                // ListView
                que.Enqueue(_tmp["product_number"].ToString());
                que.Enqueue(_tmp["product_name"].ToString());
                que.Enqueue(_tmp["bilichi1"].ToString());
                que.Enqueue(_tmp["bilichi2"].ToString());

                ClassListViewOperate.AddOneRow(ref listView_Param, que);
                que.Clear();
            }
            catch
            {
                //MessageBox.Show(ex.Message);
            }
        }

        private void btn_SaveLength_Click(object sender, EventArgs e)
        {
            try
            {
                int zongchang1 = int.Parse(txt_1zongchang.Text.Trim());
                int zongchang2 = int.Parse(txt_2zongchang.Text.Trim());
                int yuchuxian1 = int.Parse(txt_1yuchuchang.Text.Trim());
                int yuchuxian2 = int.Parse(txt_2yuchuchang.Text.Trim());
                int mansu = int.Parse(txt_mansuchang.Text.Trim());
                int jiasu = int.Parse(txt_jiasuchang.Text.Trim());
                int jiansu = int.Parse(txt_jiansuchang.Text.Trim());

                string sql = string.Format("SELECT COUNT(*) AS cnt FROM tb_Length WHERE product_number='{0}'", ProductNumber);
                DataSet ds = SQLiteHelper.ExecuteDataset(sql);
                DataTable dt = ds.Tables[0];
                int cnt = int.Parse(dt.Rows[0]["cnt"].ToString());
                if (cnt == 0) // 记录是否存在，不存在则生成，否则更新
                {
                    Queue queue = new Queue();
                    queue.Enqueue(ProductNumber);
                    queue.Enqueue(ProductName);
                    queue.Enqueue(zongchang1.ToString());
                    queue.Enqueue(zongchang2.ToString());
                    queue.Enqueue(yuchuxian1.ToString());
                    queue.Enqueue(yuchuxian2.ToString());
                    queue.Enqueue(mansu.ToString());
                    queue.Enqueue(jiasu.ToString());
                    queue.Enqueue(jiansu.ToString());

                    sql = string.Format("INSERT INTO tb_Length VALUES('{0}','{1}',{2},{3},{4},{5},{6},{7},{8})",
                        ProductName, ProductNumber, zongchang1,zongchang2,yuchuxian1,yuchuxian2,mansu,jiasu,jiansu);

                    if (SQLiteHelper.ExecuteNonQuery(sql) > 0)
                    {
                        ClassListViewOperate.AddOneRow(ref listView_Length, queue);
                        MessageBox.Show("写入成功！");
                    }
                }
                else
                {
                    sql = string.Format("UPDATE tb_Length SET zongchang1={0},zongchang2={1},yuchuchang1={2},yuchuchang2={3},mansuchang={4},jiasuchang={5},jiansuchang={6} WHERE product_number='{7}'",
                        zongchang1, zongchang2, yuchuxian1, yuchuxian2, mansu, jiansu, jiansu, ProductNumber);
                    if (SQLiteHelper.ExecuteNonQuery(sql) > 0)
                    {

                        foreach (ListViewItem item in listView_Length.Items)
                        {

                            string selectCode = item.SubItems[0].Text.Trim();
                            if (ProductNumber == selectCode)
                            {
                                item.SubItems[2].Text = zongchang1.ToString();
                                item.SubItems[3].Text = zongchang2.ToString();
                                item.SubItems[4].Text = yuchuxian1.ToString();
                                item.SubItems[5].Text = yuchuxian2.ToString();
                                item.SubItems[6].Text = mansu.ToString();
                                item.SubItems[7].Text = jiasu.ToString();
                                item.SubItems[8].Text = jiansu.ToString();
                                break;
                            }
                        }
                        MessageBox.Show("更新完成！");
                    }
                }
            }
            catch
            {
                MessageBox.Show("数据输入有误，请重新输入！");
            }
        }

        private void btn_DelLength_Click(object sender, EventArgs e)
        {
            int j = 0;

            foreach (ListViewItem item in listView_Length.Items)
            {
                if (item.Checked)
                {
                    j++;
                }
            }

            if (j == 0)
            {
                MessageBox.Show("请选择要删除的数据！");
            }

            try
            {
                foreach (ListViewItem item in listView_Length.Items)
                {
                    if (item.Checked)
                    {
                        if (MessageBox.Show("请确认是否真的删除?", "友情提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes)
                        {
                            string productCode = item.SubItems[0].Text.Trim();
                            string sql = string.Format("DELETE FROM tb_Length WHERE product_number='{0}'", productCode);
                            if (SQLiteHelper.ExecuteNonQuery(sql) > 0)
                            {
                                listView_Length.Items.Remove(item);
                                break;
                            }
                        }
                    }
                }
            }
            catch
            {
                // MessageBox.Show(ex.Message);
            }
        }

        private void listView_Length_ItemCheck(object sender, ItemCheckEventArgs e)
        {
            if (!listView_Length.Items[e.Index].Checked)
            {
                foreach (ListViewItem lv in listView_Length.Items)
                {
                    if (lv.Checked)
                    {
                        lv.Checked = false;
                        lv.Selected = false;
                    }
                }
                listView_Length.Items[e.Index].Selected = true;
            }
        }

        private void listView_Length_SelectedIndexChanged(object sender, EventArgs e)
        {
            foreach (ListViewItem lv in listView_Length.Items)
            {
                if (lv.Selected)
                {
                    lv.Checked = true;
                }
                else
                {
                    if (listView_Length.SelectedIndices.Count > 0)
                    {
                        if (lv.Checked)
                        {
                            lv.Checked = false;
                        }
                    }
                }
            }
            try
            {
                int index = listView_Length.SelectedIndices[0];
                ListViewItem selecteditem = listView_Length.Items[index];
                txt_1zongchang.Text = selecteditem.SubItems[2].Text;
                txt_2zongchang.Text = selecteditem.SubItems[3].Text;
                txt_1yuchuchang.Text = selecteditem.SubItems[4].Text;
                txt_2yuchuchang.Text = selecteditem.SubItems[5].Text;
                txt_mansuchang.Text = selecteditem.SubItems[6].Text;
                txt_jiasuchang.Text = selecteditem.SubItems[7].Text;
                txt_jiansuchang.Text = selecteditem.SubItems[8].Text;

                foreach (ListViewItem item in listView_Length.Items)
                {
                    if (item.SubItems[0].Text == ProductNumber)
                    {
                        item.Checked = true;
                    }
                    else
                    {
                        item.Checked = false;
                    }
                }
            }
            catch
            {
            }
        }

        private void btn_SaveSpeed_Click(object sender, EventArgs e)
        {
            try
            {
                int songbu = int.Parse(txt_songbu.Text.Trim());
                int chuanbu = int.Parse(txt_chuanbu.Text.Trim());
                int xuanbu = int.Parse(txt_xuanbu.Text.Trim());
                int raoxianman = int.Parse(txt_raoxianman.Text.Trim());
                int raoxiankuai = int.Parse(txt_raoxiankuai.Text.Trim());

                string sql = string.Format("SELECT COUNT(*) AS cnt FROM tb_Speed WHERE product_number='{0}'", ProductNumber);
                DataSet ds = SQLiteHelper.ExecuteDataset(sql);
                DataTable dt = ds.Tables[0];
                int cnt = int.Parse(dt.Rows[0]["cnt"].ToString());
                if (cnt == 0) // 记录是否存在，不存在则生成，否则更新
                {
                    Queue queue = new Queue();
                    queue.Enqueue(ProductNumber);
                    queue.Enqueue(ProductName);
                    queue.Enqueue(songbu.ToString());
                    queue.Enqueue(chuanbu.ToString());
                    queue.Enqueue(xuanbu.ToString());
                    queue.Enqueue(raoxianman.ToString());
                    queue.Enqueue(raoxiankuai.ToString());

                    sql = string.Format("INSERT INTO tb_Speed VALUES('{0}','{1}',{2},{3},{4},{5},{6})",
                        ProductName, ProductNumber, songbu, chuanbu, xuanbu, raoxianman, raoxiankuai);

                    if (SQLiteHelper.ExecuteNonQuery(sql) > 0)
                    {
                        ClassListViewOperate.AddOneRow(ref listView_Speed, queue);
                        MessageBox.Show("写入成功！");
                    }
                }
                else
                {
                    sql = string.Format("UPDATE tb_Speed SET songbu={0},chuanbu={1},xuanbu={2},raoxianman={3},raoxiankuai={4} WHERE product_number='{5}'",
                        songbu, chuanbu, xuanbu, raoxianman, raoxiankuai, ProductNumber);
                    if (SQLiteHelper.ExecuteNonQuery(sql) > 0)
                    {

                        foreach (ListViewItem item in listView_Speed.Items)
                        {

                            string selectCode = item.SubItems[0].Text.Trim();
                            if (ProductNumber == selectCode)
                            {
                                item.SubItems[2].Text = songbu.ToString();
                                item.SubItems[3].Text = chuanbu.ToString();
                                item.SubItems[4].Text = xuanbu.ToString();
                                item.SubItems[5].Text = raoxianman.ToString();
                                item.SubItems[6].Text = raoxiankuai.ToString();
                                break;
                            }
                        }
                        MessageBox.Show("更新完成！");
                    }
                }
            }
            catch
            {
                MessageBox.Show("数据输入有误，请重新输入！");
            }
        }

        private void btn_DelSpeed_Click(object sender, EventArgs e)
        {
            int j = 0;

            foreach (ListViewItem item in listView_Speed.Items)
            {
                if (item.Checked)
                {
                    j++;
                }
            }

            if (j == 0)
            {
                MessageBox.Show("请选择要删除的数据！");
            }

            try
            {
                foreach (ListViewItem item in listView_Speed.Items)
                {
                    if (item.Checked)
                    {
                        if (MessageBox.Show("请确认是否真的删除?", "友情提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes)
                        {
                            string productCode = item.SubItems[0].Text.Trim();
                            string sql = string.Format("DELETE FROM tb_Speed WHERE product_number='{0}'", productCode);
                            if (SQLiteHelper.ExecuteNonQuery(sql) > 0)
                            {
                                listView_Speed.Items.Remove(item);
                                break;
                            }
                        }
                    }
                }
            }
            catch
            {
                // MessageBox.Show(ex.Message);
            }
        }

        private void listView_Speed_ItemCheck(object sender, ItemCheckEventArgs e)
        {
            if (!listView_Speed.Items[e.Index].Checked)
            {
                foreach (ListViewItem lv in listView_Speed.Items)
                {
                    if (lv.Checked)
                    {
                        lv.Checked = false;
                        lv.Selected = false;
                    }
                }
                listView_Speed.Items[e.Index].Selected = true;
            }
        }

        private void listView_Speed_SelectedIndexChanged(object sender, EventArgs e)
        {
            foreach (ListViewItem lv in listView_Speed.Items)
            {
                if (lv.Selected)
                {
                    lv.Checked = true;
                }
                else
                {
                    if (listView_Speed.SelectedIndices.Count > 0)
                    {
                        if (lv.Checked)
                        {
                            lv.Checked = false;
                        }
                    }
                }
            }
            try
            {
                int index = listView_Speed.SelectedIndices[0];
                ListViewItem selecteditem = listView_Speed.Items[index];
                txt_songbu.Text = selecteditem.SubItems[2].Text;
                txt_chuanbu.Text = selecteditem.SubItems[3].Text;
                txt_xuanbu.Text = selecteditem.SubItems[4].Text;
                txt_raoxianman.Text = selecteditem.SubItems[5].Text;
                txt_raoxiankuai.Text = selecteditem.SubItems[6].Text;

                foreach (ListViewItem item in listView_Speed.Items)
                {
                    if (item.SubItems[0].Text == ProductNumber)
                    {
                        item.Checked = true;
                    }
                    else
                    {
                        item.Checked = false;
                    }
                }
            }
            catch
            {
            }
        }

        private void btn_SaveDelay_Click(object sender, EventArgs e)
        {
            try
            {
                int shangjia1 = int.Parse(txt_shangjia1.Text.Trim());
                int ding1 = int.Parse(txt_ding1.Text.Trim());
                int xiaxi1 = int.Parse(txt_xiaxi1.Text.Trim());
                int shangjia2 = int.Parse(txt_shangjia2.Text.Trim());
                int ding2 = int.Parse(txt_ding2.Text.Trim());
                int xiaxi2 = int.Parse(txt_xiaxi2.Text.Trim());
                int shangda1 = int.Parse(txt_shangda1.Text.Trim());
                int qie1 = int.Parse(txt_qie1.Text.Trim());
                int chu = int.Parse(txt_chu.Text.Trim());
                int shangda2 = int.Parse(txt_shangda2.Text.Trim());
                int qie2 = int.Parse(txt_qie2.Text.Trim());

                string sql = string.Format("SELECT COUNT(*) AS cnt FROM tb_Delay WHERE product_number='{0}'", ProductNumber);
                DataSet ds = SQLiteHelper.ExecuteDataset(sql);
                DataTable dt = ds.Tables[0];
                int cnt = int.Parse(dt.Rows[0]["cnt"].ToString());
                if (cnt == 0) // 记录是否存在，不存在则生成，否则更新
                {
                    Queue queue = new Queue();
                    queue.Enqueue(ProductNumber);
                    queue.Enqueue(ProductName);
                    queue.Enqueue(shangjia1.ToString());
                    queue.Enqueue(ding1.ToString());
                    queue.Enqueue(xiaxi1.ToString());
                    queue.Enqueue(shangjia2.ToString());
                    queue.Enqueue(ding2.ToString());
                    queue.Enqueue(xiaxi2.ToString());
                    queue.Enqueue(shangda1.ToString());
                    queue.Enqueue(qie1.ToString());
                    queue.Enqueue(chu.ToString());
                    queue.Enqueue(shangda2.ToString());
                    queue.Enqueue(qie2.ToString());
                    sql = string.Format("INSERT INTO tb_Delay VALUES('{0}','{1}',{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12})",
                        ProductName, ProductNumber, shangjia1, ding1, xiaxi1, shangjia2, ding2, xiaxi2, shangda1,qie1,chu,shangda2,qie2);

                    if (SQLiteHelper.ExecuteNonQuery(sql) > 0)
                    {
                        ClassListViewOperate.AddOneRow(ref listView_Delay, queue);
                        MessageBox.Show("写入成功！");
                    }
                }
                else
                {
                    sql = string.Format("UPDATE tb_Delay SET shangjia1={0},ding1={1},xiaxi1={2},shangjia2={3},ding2={4},xiaxi2={5},shangda1={6},qie1={7},chu={8},shangda2={9},qie2={10} WHERE product_number='{11}'",
                        shangjia1, ding1, xiaxi1, shangjia2, ding2, xiaxi2, shangda1,qie1,chu,shangda2,qie2, ProductNumber);
                    if (SQLiteHelper.ExecuteNonQuery(sql) > 0)
                    {

                        foreach (ListViewItem item in listView_Delay.Items)
                        {

                            string selectCode = item.SubItems[0].Text.Trim();
                            if (ProductNumber == selectCode)
                            {
                                item.SubItems[2].Text = shangjia1.ToString();
                                item.SubItems[3].Text = ding1.ToString();
                                item.SubItems[4].Text = xiaxi1.ToString();
                                item.SubItems[5].Text = shangjia2.ToString();
                                item.SubItems[6].Text = ding2.ToString();
                                item.SubItems[7].Text = xiaxi2.ToString();
                                item.SubItems[8].Text = shangda1.ToString();
                                item.SubItems[9].Text = qie1.ToString();
                                item.SubItems[10].Text = chu.ToString();
                                item.SubItems[11].Text = shangda2.ToString();
                                item.SubItems[12].Text = qie2.ToString();
                                break;
                            }
                        }
                        MessageBox.Show("更新完成！");
                    }
                }
            }
            catch
            {
                MessageBox.Show("数据输入有误，请重新输入！");
            }
        }

        private void listView_Delay_ItemCheck(object sender, ItemCheckEventArgs e)
        {
            if (!listView_Delay.Items[e.Index].Checked)
            {
                foreach (ListViewItem lv in listView_Delay.Items)
                {
                    if (lv.Checked)
                    {
                        lv.Checked = false;
                        lv.Selected = false;
                    }
                }
                listView_Delay.Items[e.Index].Selected = true;
            }
        }

        private void listView_Delay_SelectedIndexChanged(object sender, EventArgs e)
        {
            foreach (ListViewItem lv in listView_Delay.Items)
            {
                if (lv.Selected)
                {
                    lv.Checked = true;
                }
                else
                {
                    if (listView_Delay.SelectedIndices.Count > 0)
                    {
                        if (lv.Checked)
                        {
                            lv.Checked = false;
                        }
                    }
                }
            }
            try
            {
                int index = listView_Delay.SelectedIndices[0];
                ListViewItem selecteditem = listView_Delay.Items[index];
                txt_shangjia1.Text = selecteditem.SubItems[2].Text;
                txt_ding1.Text = selecteditem.SubItems[3].Text;
                txt_xiaxi1.Text = selecteditem.SubItems[4].Text;
                txt_shangjia2.Text = selecteditem.SubItems[5].Text;
                txt_ding2.Text = selecteditem.SubItems[6].Text;
                txt_xiaxi2.Text = selecteditem.SubItems[7].Text;
                txt_shangda1.Text = selecteditem.SubItems[8].Text;
                txt_qie1.Text = selecteditem.SubItems[9].Text;
                txt_chu.Text = selecteditem.SubItems[10].Text;
                txt_shangda2.Text = selecteditem.SubItems[11].Text;
                txt_qie2.Text = selecteditem.SubItems[12].Text;

                foreach (ListViewItem item in listView_Delay.Items)
                {
                    if (item.SubItems[0].Text == ProductNumber)
                    {
                        item.Checked = true;
                    }
                    else
                    {
                        item.Checked = false;
                    }
                }
            }
            catch
            {
            }
        }

        private void btn_SaveParam_Click(object sender, EventArgs e)
        {
            try
            {
                int songzhoujia = int.Parse(txt_songzhoujia.Text.Trim());
                int songzhoujian = int.Parse(txt_songzhoujian.Text.Trim());
                int chuanzhoujia = int.Parse(txt_chuanzhoujia.Text.Trim());
                int chuanzhoujian = int.Parse(txt_chuanzhoujian.Text.Trim());
                int xuanzhoujia = int.Parse(txt_xuanzhoujia.Text.Trim());
                int xuanzhoujian = int.Parse(txt_xuanzhoujian.Text.Trim());
                int raozhoujia = int.Parse(txt_raozhoujia.Text.Trim());
                int raozhoujian = int.Parse(txt_raozhoujian.Text.Trim());
                int fu1 = int.Parse(txt_fu1.Text.Trim());
                int fu2 = int.Parse(txt_fu2.Text.Trim());
                int xuan1 = int.Parse(txt_xuan1.Text.Trim());
                int xuan2 = int.Parse(txt_xuan2.Text.Trim());

                string sql = string.Format("SELECT COUNT(*) AS cnt FROM tb_Parameter WHERE product_number='{0}'", ProductNumber);
                DataSet ds = SQLiteHelper.ExecuteDataset(sql);
                DataTable dt = ds.Tables[0];
                int cnt = int.Parse(dt.Rows[0]["cnt"].ToString());
                if (cnt == 0) // 记录是否存在，不存在则生成，否则更新
                {
                    Queue queue = new Queue();
                    queue.Enqueue(ProductNumber);
                    queue.Enqueue(ProductName);
                    queue.Enqueue(songzhoujia.ToString());
                    queue.Enqueue(songzhoujian.ToString());
                    queue.Enqueue(chuanzhoujia.ToString());
                    queue.Enqueue(chuanzhoujian.ToString());
                    queue.Enqueue(xuanzhoujia.ToString());
                    queue.Enqueue(xuanzhoujian.ToString());
                    queue.Enqueue(raozhoujia.ToString());
                    queue.Enqueue(raozhoujian.ToString());
                    queue.Enqueue(fu1.ToString());
                    queue.Enqueue(fu2.ToString());
                    queue.Enqueue(xuan1.ToString());
                    queue.Enqueue(xuan2.ToString());

                    sql = string.Format("INSERT INTO tb_Parameter VALUES('{0}','{1}',{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12},{13})",
                        ProductName, ProductNumber, songzhoujia,songzhoujian,chuanzhoujia,chuanzhoujian,xuanzhoujia,xuanzhoujian,raozhoujia,raozhoujian,fu1,fu2,xuan1,xuan2);

                    if (SQLiteHelper.ExecuteNonQuery(sql) > 0)
                    {
                        ClassListViewOperate.AddOneRow(ref listView_Param, queue);
                        MessageBox.Show("写入成功！");
                    }
                }
                else
                {
                    sql = string.Format("UPDATE tb_Parameter SET songzhoujia={0},songzhoujian={1},chuanzhoujia={2},chuanzhoujian={3},xuanzhoujia={4},xuanzhoujian={5},raozhoujia={6},raozhoujian={7},fu1={8},fu2={9},xuan1={10},xuan2={11} WHERE product_number='{12}'",
                       songzhoujia,songzhoujian,chuanzhoujia,chuanzhoujian,xuanzhoujia,xuanzhoujian,raozhoujia,raozhoujian,fu1,fu2,xuan1,xuan2, ProductNumber);
                    if (SQLiteHelper.ExecuteNonQuery(sql) > 0)
                    {

                        foreach (ListViewItem item in listView_Param.Items)
                        {

                            string selectCode = item.SubItems[0].Text.Trim();
                            if (ProductNumber == selectCode)
                            {
                                item.SubItems[2].Text = songzhoujia.ToString();
                                item.SubItems[3].Text = songzhoujian.ToString();
                                item.SubItems[4].Text = chuanzhoujia.ToString();
                                item.SubItems[5].Text = chuanzhoujian.ToString();
                                item.SubItems[6].Text = xuanzhoujia.ToString();
                                item.SubItems[7].Text = xuanzhoujian.ToString();
                                item.SubItems[8].Text = raozhoujia.ToString();
                                item.SubItems[9].Text = raozhoujian.ToString();
                                item.SubItems[10].Text = fu1.ToString();
                                item.SubItems[11].Text = fu2.ToString();
                                item.SubItems[12].Text = xuan1.ToString();
                                item.SubItems[13].Text = xuan2.ToString();
                                break;
                            }
                        }
                        MessageBox.Show("更新完成！");
                    }
                }
            }
            catch
            {
                MessageBox.Show("数据输入有误，请重新输入！");
            }
        }

        private void btn_DelParam_Click(object sender, EventArgs e)
        {
            int j = 0;

            foreach (ListViewItem item in listView_Param.Items)
            {
                if (item.Checked)
                {
                    j++;
                }
            }

            if (j == 0)
            {
                MessageBox.Show("请选择要删除的数据！");
            }

            try
            {
                foreach (ListViewItem item in listView_Param.Items)
                {
                    if (item.Checked)
                    {
                        if (MessageBox.Show("请确认是否真的删除?", "友情提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes)
                        {
                            string productCode = item.SubItems[0].Text.Trim();
                            string sql = string.Format("DELETE FROM tb_Parameter WHERE product_number='{0}'", productCode);
                            if (SQLiteHelper.ExecuteNonQuery(sql) > 0)
                            {
                                listView_Param.Items.Remove(item);
                                break;
                            }
                        }
                    }
                }
            }
            catch
            {
                // MessageBox.Show(ex.Message);
            }
        }

        private void listView_Param_ItemCheck(object sender, ItemCheckEventArgs e)
        {
            if (!listView_Param.Items[e.Index].Checked)
            {
                foreach (ListViewItem lv in listView_Param.Items)
                {
                    if (lv.Checked)
                    {
                        lv.Checked = false;
                        lv.Selected = false;
                    }
                }
                listView_Param.Items[e.Index].Selected = true;
            }
        }

        private void listView_Param_SelectedIndexChanged(object sender, EventArgs e)
        {
            foreach (ListViewItem lv in listView_Param.Items)
            {
                if (lv.Selected)
                {
                    lv.Checked = true;
                }
                else
                {
                    if (listView_Param.SelectedIndices.Count > 0)
                    {
                        if (lv.Checked)
                        {
                            lv.Checked = false;
                        }
                    }
                }
            }
            try
            {
                int index = listView_Param.SelectedIndices[0];
                ListViewItem selecteditem = listView_Param.Items[index];
                txt_songzhoujia.Text = selecteditem.SubItems[2].Text;
                txt_songzhoujian.Text = selecteditem.SubItems[3].Text;
                txt_chuanzhoujia.Text = selecteditem.SubItems[4].Text;
                txt_chuanzhoujian.Text = selecteditem.SubItems[5].Text;
                txt_xuanzhoujia.Text = selecteditem.SubItems[6].Text;
                txt_xuanzhoujian.Text = selecteditem.SubItems[7].Text;
                txt_raozhoujia.Text = selecteditem.SubItems[8].Text;
                txt_raozhoujian.Text = selecteditem.SubItems[9].Text;
                txt_fu1.Text = selecteditem.SubItems[10].Text;
                txt_fu2.Text = selecteditem.SubItems[11].Text;
                txt_xuan1.Text = selecteditem.SubItems[12].Text;
                txt_xuan2.Text = selecteditem.SubItems[13].Text;

                foreach (ListViewItem item in listView_Param.Items)
                {
                    if (item.SubItems[0].Text == ProductNumber)
                    {
                        item.Checked = true;
                    }
                    else
                    {
                        item.Checked = false;
                    }
                }
            }
            catch
            {
            }
        }

        private void btn_DelDelay_Click(object sender, EventArgs e)
        {
            int j = 0;

            foreach (ListViewItem item in listView_Delay.Items)
            {
                if (item.Checked)
                {
                    j++;
                }
            }

            if (j == 0)
            {
                MessageBox.Show("请选择要删除的数据！");
            }

            try
            {
                foreach (ListViewItem item in listView_Delay.Items)
                {
                    if (item.Checked)
                    {
                        if (MessageBox.Show("请确认是否真的删除?", "友情提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes)
                        {
                            string productCode = item.SubItems[0].Text.Trim();
                            string sql = string.Format("DELETE FROM tb_Delay WHERE product_number='{0}'", productCode);
                            if (SQLiteHelper.ExecuteNonQuery(sql) > 0)
                            {
                                listView_Delay.Items.Remove(item);
                                break;
                            }
                        }
                    }
                }
            }
            catch
            {
                // MessageBox.Show(ex.Message);
            }
        }

        private void btn_Savebilichi_Click(object sender, EventArgs e)
        {
            try
            {
                int bilichi1 = int.Parse(txt_bilichi1.Text.Trim());
                int bilichi2 = int.Parse(txt_bilichi2.Text.Trim());

                string sql = string.Format("SELECT COUNT(*) AS cnt FROM tb_bilichi WHERE product_number='{0}'", ProductNumber);
                DataSet ds = SQLiteHelper.ExecuteDataset(sql);
                DataTable dt = ds.Tables[0];
                int cnt = int.Parse(dt.Rows[0]["cnt"].ToString());
                if (cnt == 0) // 记录是否存在，不存在则生成，否则更新
                {
                    Queue queue = new Queue();
                    queue.Enqueue(ProductNumber);
                    queue.Enqueue(ProductName);
                    queue.Enqueue(bilichi1.ToString());
                    queue.Enqueue(bilichi2.ToString());

                    sql = string.Format("INSERT INTO tb_bilichi VALUES('{0}','{1}',{2},{3},{4})",
                        ProductName, ProductNumber, Data.nuanji_time, bilichi1,bilichi2);

                    if (SQLiteHelper.ExecuteNonQuery(sql) > 0)
                    {
                        ClassListViewOperate.AddOneRow(ref listView_bilichi, queue);
                        MessageBox.Show("写入成功！");
                    }
                }
                else
                {
                    sql = string.Format("UPDATE tb_bilichi SET nuanji_time={0},bilichi1={1},bilichi2={2} WHERE product_number='{3}'",
                       Data.nuanji_time,bilichi1,bilichi2, ProductNumber);
                    if (SQLiteHelper.ExecuteNonQuery(sql) > 0)
                    {

                        foreach (ListViewItem item in listView_bilichi.Items)
                        {

                            string selectCode = item.SubItems[0].Text.Trim();
                            if (ProductNumber == selectCode)
                            {
                                item.SubItems[2].Text = bilichi1.ToString();
                                item.SubItems[3].Text = bilichi2.ToString();
                                break;
                            }
                        }
                        MessageBox.Show("更新完成！");
                    }
                }
            }
            catch
            {
                MessageBox.Show("数据输入有误，请重新输入！");
            }
        }

        private void btn_Delbilichi_Click(object sender, EventArgs e)
        {
            int j = 0;

            foreach (ListViewItem item in listView_bilichi.Items)
            {
                if (item.Checked)
                {
                    j++;
                }
            }

            if (j == 0)
            {
                MessageBox.Show("请选择要删除的数据！");
            }

            try
            {
                foreach (ListViewItem item in listView_bilichi.Items)
                {
                    if (item.Checked)
                    {
                        if (MessageBox.Show("请确认是否真的删除?", "友情提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes)
                        {
                            string productCode = item.SubItems[0].Text.Trim();
                            string sql = string.Format("DELETE FROM tb_bilichi WHERE product_number='{0}'", productCode);
                            if (SQLiteHelper.ExecuteNonQuery(sql) > 0)
                            {
                                listView_bilichi.Items.Remove(item);
                                break;
                            }
                        }
                    }
                }
            }
            catch
            {
                // MessageBox.Show(ex.Message);
            }
        }

        private void listView_bilichi_ItemCheck(object sender, ItemCheckEventArgs e)
        {
            if (!listView_bilichi.Items[e.Index].Checked)
            {
                foreach (ListViewItem lv in listView_bilichi.Items)
                {
                    if (lv.Checked)
                    {
                        lv.Checked = false;
                        lv.Selected = false;
                    }
                }
                listView_bilichi.Items[e.Index].Selected = true;
            }
        }

        private void listView_bilichi_SelectedIndexChanged(object sender, EventArgs e)
        {
            foreach (ListViewItem lv in listView_bilichi.Items)
            {
                if (lv.Selected)
                {
                    lv.Checked = true;
                }
                else
                {
                    if (listView_bilichi.SelectedIndices.Count > 0)
                    {
                        if (lv.Checked)
                        {
                            lv.Checked = false;
                        }
                    }
                }
            }
            try
            {
                int index = listView_bilichi.SelectedIndices[0];
                ListViewItem selecteditem = listView_bilichi.Items[index];
                txt_bilichi1.Text = selecteditem.SubItems[2].Text;
                txt_bilichi2.Text = selecteditem.SubItems[3].Text;

                foreach (ListViewItem item in listView_bilichi.Items)
                {
                    if (item.SubItems[0].Text == ProductNumber)
                    {
                        item.Checked = true;
                    }
                    else
                    {
                        item.Checked = false;
                    }
                }
            }
            catch
            {
            }
        }

        private void btn_bilichi1_Click(object sender, EventArgs e)
        {
            try
            {
                KeyBoardForm _frm_KeyBoardForm = new KeyBoardForm();
                _frm_KeyBoardForm.ShowDialog();
                if (_frm_KeyBoardForm.IsOk)
                {
                    txt_bilichi1.Text = _frm_KeyBoardForm.ReturnValue;
                }
                _frm_KeyBoardForm.Dispose();
            }
            catch
            {
            }
        }

        private void btn_bilichi2_Click(object sender, EventArgs e)
        {
            try
            {
                KeyBoardForm _frm_KeyBoardForm = new KeyBoardForm();
                _frm_KeyBoardForm.ShowDialog();
                if (_frm_KeyBoardForm.IsOk)
                {
                    txt_bilichi2 .Text = _frm_KeyBoardForm.ReturnValue;
                }
                _frm_KeyBoardForm.Dispose();
            }
            catch
            {
            }
        }
    }
}